﻿Imports System.IO
Imports System.IO.Compression
Imports System.Text

Public Class Compression
    Public Shared Function DeflateString(text As String) As String
        Using mstream = New MemoryStream()
            Using zstream = New DeflateStream(mstream, CompressionMode.Compress)
                Using twriter = New StreamWriter(zstream, Encoding.UTF8)
                    twriter.Write(text)
                End Using
            End Using
            Return Convert.ToBase64String(mstream.ToArray())
        End Using
    End Function
    Public Shared Function InflateString(base64 As String) As String
        Using mstream = New MemoryStream(Convert.FromBase64String(base64))
            Using zstream = New DeflateStream(mstream, CompressionMode.Decompress)
                Using treader = New StreamReader(zstream)
                    Return treader.ReadToEnd()
                End Using
            End Using
        End Using
    End Function
End Class
